package com.yc.plugin.app.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.yc.commontlib.base.YcBaseViewModel
import com.yc.commontlib.net.YcResult
import com.yc.commontlib.net.YcRetrofitUtil
import com.yc.plugin.app.data.json.PluginVersionJson
import com.yc.plugin.app.net.PluginApiService
import com.yc.plugin.app.repository.PluginVersionRepository
import kotlinx.coroutines.flow.collectLatest

/**
 * Creator: yc
 * Date: 2021/6/15 18:03
 * UseDes:
 */
class PluginWelcomeVM : YcBaseViewModel() {
    private val mApiService: PluginApiService by lazy {
        YcRetrofitUtil.Instance.getApiService(PluginApiService::class.java)
    }
    private val mVersionRepository: PluginVersionRepository by lazy { PluginVersionRepository(mApiService) }


    private val _mVersion = MutableLiveData<YcResult<PluginVersionJson>>()
    val mVersion: LiveData<YcResult<PluginVersionJson>> = _mVersion
    fun checkVersion() = launch {
        mVersionRepository.getVersion().collectLatest {
            _mVersion.postValue(it)
        }
    }
}